home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Science / RLaB / help / FOR < prev    next >
Text File  |  1994-04-25  |  1KB  |  50 lines

  1. FOR:
  2.  
  3.     The RLaB for statement is NOT similar to the C for statement.
  4.     The correct usage is best shown by example...
  5.  
  6.     Example:
  7.  
  8.     > for(i in 1:4) {
  9.     >   for(j in 1:5) {
  10.     >     m[i;j] = i+j;
  11.     >   }
  12.     > }
  13.  
  14.     The above shows a nested set of for statements. i and j are
  15.     automatically initialized to have the values of the vector
  16.     expressions `1:4' and `1:5'. Each loop proceeds until i and j
  17.     have been assigned each element of their respective vector
  18.     expressions.
  19.  
  20.     The vector in the for statement can be any expression that
  21.     evaluates to a SCALAR or a MATRIX. If the expression evaluates
  22.     to a SCALAR the body of the for statement is executed ONCE. If
  23.     the expression evaluates to an empty-matrix ( `[]' ), then the
  24.     loop is not executed at all.
  25.  
  26.     The for statement can be also be used to loop through the
  27.     elements of a LIST.
  28.  
  29.     Example:
  30.  
  31.     > xlist = << Mass = sqrt(200); Inertia = eye(3,3); xdot = [1,2,3] >>
  32.        Inertia      Mass         xdot         
  33.     > for( i in members(xlist) )
  34.       {
  35.         xlist.[i]
  36.       }
  37.      Inertia =
  38.      matrix columns 1 thru 3
  39.                1           0           0
  40.                0           1           0
  41.                0           0           1
  42.      Mass =
  43.            14.14
  44.      xdot =
  45.      matrix columns 1 thru 3
  46.            1           2           3
  47.  
  48.  
  49. See Also: VECTOR
  50.